#include<iostream>

#include<stdio.h>

#include<pthread.h>

#include<unistd.h>

#include<string>

#include<vector>

#include<time.h>

#include<queue>

typedef void (*callback_t)();

static int num = 1;

using namespace std;

class Thread
{
public:
    static void *Routine(void *args)
    {
        Thread* thread = static_cast<Thread*>(args);
        thread->Entery();
        return nullptr;
    }

    Thread(callback_t cb):tid_(0), name_(""), start_timestamp_(0), isrunning_(false),cb_(cb)
    {}

    void Run()
    {
        name_ = "thread-" + std::to_string(num++);
        start_timestamp_ = time(nullptr);
        isrunning_ = true;
        pthread_create(&tid_, nullptr, Routine, this);
    }

    void Join()
    {
        pthread_join(tid_, nullptr);
        isrunning_ = false;
    }

    std::string Name()
    {
        return name_;
    }

    uint64_t StartTimestamp()
    {
        return start_timestamp_;
    }

    bool IsRunning()
    {
        return isrunning_;
    }

    void Entery()
    {
        cb_(); // 可以传参
    }

    ~Thread()
    {}

private:
    pthread_t tid_;
    std::string name_;
    uint64_t start_timestamp_;
    bool isrunning_;

    callback_t cb_;
};

void Print()
{
    while(true)
    {
        printf("我是线程\n");
        sleep(1);
    }
}

int main()
{
    std::vector<Thread> threads;

    for(int i = 0 ;i < 10; i++)
    {
        threads.push_back(Thread(Print));
    }

    for(auto &t : threads)
    {
        t.Run();
    }
    
    // for(auto &t : threads)
    // {
    //     t.Join();
    // }

    return 0;
}